cmake_minimum_required(VERSION 3.8)
project(center_detection_second)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(lifecycle_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(PCL REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(PCL REQUIRED COMPONENTS common filters)
find_package(tf2_geometry_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(OpenCV REQUIRED)

include_directories(
  include
  ${EIGEN3_INCLUDE_DIR}
  ${OpenCV_INCLUDE_DIRS}
  ${PCL_INCLUDE_DIRS}
)

add_library(center_detector_second_lib
  src/neutron_detector.cpp
  src/gamma_detector.cpp
  src/detection_manager.cpp
)

# 链接库
ament_target_dependencies(center_detector_second_lib
  rclcpp
  rclcpp_lifecycle
  lifecycle_msgs
  std_msgs
  sensor_msgs
  geometry_msgs
  pcl_conversions
  tf2
  tf2_ros
  visualization_msgs
  tf2_geometry_msgs
)

#库文件链接
target_link_libraries(center_detector_second_lib
    Eigen3::Eigen
    ${PCL_LIBRARIES}
    ${sensor_msgs_LIBRARIES}
    ${geometry_msgs_LIBRARIES}
    ${pcl_conversions_LIBRARIES}
    ${OpenCV_LIBS}
)

target_compile_definitions(center_detector_second_lib PUBLIC PCL_NO_PRECOMPILE)

# 添加可执行文件
add_executable(center_detector_second src/center_detector.cpp)
ament_target_dependencies(center_detector_second
  rclcpp
  sensor_msgs
  geometry_msgs
  std_msgs
  pcl_conversions
  tf2_ros
)
target_link_libraries(center_detector_second
  center_detector_second_lib
  ${PCL_LIBRARIES}
)

target_compile_definitions(center_detector_second PUBLIC PCL_NO_PRECOMPILE)

# 安装规则
install(TARGETS
  center_detector_second_lib
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

install(TARGETS
  center_detector_second
  DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY include/
  DESTINATION include/
)

install(DIRECTORY
  config
  launch
  DESTINATION share/${PROJECT_NAME}/
)

# 导出包
ament_export_include_directories(include)
ament_export_libraries(center_detector_lib)
ament_export_dependencies(
  rclcpp 
  sensor_msgs 
  geometry_msgs 
  std_msgs 
  PCL 
  pcl_conversions 
  tf2_ros
  tf2_geometry_msgs
)


if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
